<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>${product.name} - 淘乐乐商城</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Microsoft YaHei', sans-serif;
        }

        /* 导航栏样式 */
        .nav-top {
            background: #f5f5f5;
            padding: 10px 0;
            border-bottom: 1px solid #e8e8e8;
        }

        .nav-main {
            background: #ff4d4f;
            padding: 15px 0;
            position: sticky;
            top: 0;
            z-index: 100;
        }

        .container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 0 15px;
        }

        .nav-content {
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .nav-links a {
            color: #666;
            text-decoration: none;
            margin-left: 20px;
            font-size: 14px;
        }

        .nav-links a:hover {
            color: #ff4d4f;
        }

        .logo {
            color: white;
            font-size: 24px;
            font-weight: bold;
            text-decoration: none;
        }

        /* 面包屑导航 */
        .breadcrumb {
            padding: 15px 0;
            color: #666;
            font-size: 14px;
        }

        .breadcrumb a {
            color: #666;
            text-decoration: none;
        }

        .breadcrumb a:hover {
            color: #ff4d4f;
        }

        /* 商品详情布局 */
        .product-container {
            display: grid;
            grid-template-columns: 450px 1fr;
            gap: 40px;
            margin: 20px 0;
            background: white;
            padding: 30px;
            border-radius: 8px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
        }

        /* 商品图片 */
        .product-gallery {
            position: relative;
        }

        .product-image {
            width: 100%;
            height: 450px;
            border-radius: 8px;
            object-fit: cover;
        }

        /* 商品信息 */
        .product-info {
            padding: 20px 0;
        }

        .product-title {
            font-size: 24px;
            color: #333;
            margin-bottom: 20px;
            line-height: 1.4;
        }

        .product-price {
            background: #fff1f0;
            padding: 20px;
            border-radius: 8px;
            margin-bottom: 20px;
        }

        .price-label {
            color: #666;
            font-size: 14px;
            margin-bottom: 8px;
        }

        .price-value {
            color: #ff4d4f;
            font-size: 36px;
            font-weight: bold;
        }

        .price-value::before {
            content: "¥";
            font-size: 24px;
            margin-right: 4px;
        }

        .product-meta {
            margin: 20px 0;
            padding: 20px 0;
            border-top: 1px solid #f0f0f0;
            border-bottom: 1px solid #f0f0f0;
        }

        .meta-item {
            display: flex;
            align-items: center;
            margin-bottom: 15px;
            color: #666;
        }

        .meta-label {
            width: 80px;
            color: #999;
        }

        /* 数量选择器 */
        .quantity-wrapper {
            margin: 20px 0;
        }

        .quantity-label {
            color: #666;
            margin-bottom: 10px;
        }

        .quantity-controls {
            display: inline-flex;
            align-items: center;
            border: 1px solid #ddd;
            border-radius: 4px;
        }

        .quantity-btn {
            width: 36px;
            height: 36px;
            border: none;
            background: none;
            font-size: 16px;
            cursor: pointer;
            color: #666;
        }

        .quantity-input {
            width: 60px;
            height: 36px;
            border: none;
            border-left: 1px solid #ddd;
            border-right: 1px solid #ddd;
            text-align: center;
            font-size: 16px;
        }

        /* 按钮组 */
        .action-buttons {
            display: flex;
            gap: 20px;
            margin-top: 30px;
        }

        .btn {
            flex: 1;
            height: 50px;
            border: none;
            border-radius: 25px;
            font-size: 16px;
            cursor: pointer;
            transition: all 0.3s ease;
        }

        .btn-cart {
            background: #fff0f0;
            color: #ff4d4f;
            border: 2px solid #ff4d4f;
        }

        .btn-cart:hover {
            background: #ffd6d6;
        }

        .btn-buy {
            background: #ff4d4f;
            color: white;
        }

        .btn-buy:hover {
            background: #ff6b6b;
        }

        /* 商品详情选项卡 */
        .product-tabs {
            margin-top: 40px;
        }

        .tab-headers {
            display: flex;
            border-bottom: 2px solid #f0f0f0;
            margin-bottom: 20px;
        }

        .tab-header {
            padding: 15px 30px;
            font-size: 16px;
            cursor: pointer;
            color: #666;
            border-bottom: 2px solid transparent;
            margin-bottom: -2px;
        }

        .tab-header.active {
            color: #ff4d4f;
            border-bottom-color: #ff4d4f;
        }

        .tab-content {
            padding: 20px;
            line-height: 1.8;
            color: #666;
        }
    </style>
</head>
<body>
    <!-- 顶部导航 -->
    <nav class="nav-top">
        <div class="container">
            <div class="nav-content">
                <div class="nav-links">
                    <c:choose>
                        <c:when test="${not empty sessionScope.userId}">
                            <span>欢迎，${sessionScope.username}</span>
                            <a href="logout">退出登录</a>
                        </c:when>
                        <c:otherwise>
                            <a href="login.jsp">请登录</a>
                            <a href="register.jsp">免费注册</a>
                        </c:otherwise>
                    </c:choose>
                </div>
                <div class="nav-links">
                    <a href="#"><i class="fas fa-user"></i> 我的淘乐乐</a>
                    <a href="#"><i class="fas fa-shopping-cart"></i> 购物车</a>
                    <a href="#"><i class="fas fa-heart"></i> 收藏夹</a>
                </div>
            </div>
        </div>
    </nav>

    <!-- 主导航 -->
    <nav class="nav-main">
        <div class="container">
            <div class="nav-content">
                <a href="${pageContext.request.contextPath}/taolele-mall.jsp" class="logo">淘乐乐商城</a>
            </div>
        </div>
    </nav>

    <!-- 主要内容 -->
    <div class="container">
        <!-- 面包屑导航 -->
        <div class="breadcrumb">
            <a href="${pageContext.request.contextPath}/taolele-mall.jsp">首页</a> /
            <a href="${pageContext.request.contextPath}/category?id=${product.categoryId}">分类</a> /
            <span>${product.name}</span>
        </div>

        <!-- 商品详情 -->
        <div class="product-container">
            <!-- 商品图片 -->
            <div class="product-gallery">
                <img src="${pageContext.request.contextPath}/images/${product.image}" 
                     alt="${product.name}" 
                     class="product-image">
            </div>

            <!-- 商品信息 -->
            <div class="product-info">
                <h1 class="product-title">${product.name}</h1>
                
                <div class="product-price">
                    <div class="price-label">价格</div>
                    <div class="price-value">${product.price}</div>
                </div>

                <div class="product-meta">
                    <div class="meta-item">
                        <span class="meta-label">品牌</span>
                        <span>${product.brand}</span>
                    </div>
                    <div class="meta-item">
                        <span class="meta-label">库存</span>
                        <span>${product.stock}件</span>
                    </div>
                    <div class="meta-item">
                        <span class="meta-label">上架时间</span>
                        <span><fmt:formatDate value="${product.createTime}" pattern="yyyy-MM-dd HH:mm:ss"/></span>
                    </div>
                </div>

                <!-- 数量选择 -->
                <div class="quantity-wrapper">
                    <div class="quantity-label">数量</div>
                    <div class="quantity-controls">
                        <button class="quantity-btn" onclick="updateQuantity(-1)">-</button>
                        <input type="number" class="quantity-input" value="1" min="1" max="${product.stock}" id="quantity">
                        <button class="quantity-btn" onclick="updateQuantity(1)">+</button>
                    </div>
                </div>

                <!-- 按钮组 -->
                <div class="action-buttons">
                    <button class="btn btn-cart" onclick="addToCart(${product.id})">
                        <i class="fas fa-shopping-cart"></i> 加入购物车
                    </button>
                    <button class="btn btn-buy" onclick="buyNow(${product.id})">
                        立即购买
                    </button>
                </div>
            </div>
        </div>

        <!-- 商品详情选项卡 -->
        <div class="product-tabs">
            <div class="tab-headers">
                <div class="tab-header active" onclick="switchTab(0)">商品详情</div>
                <div class="tab-header" onclick="switchTab(1)">规格参数</div>
                <div class="tab-header" onclick="switchTab(2)">用户评价</div>
            </div>
            <div class="tab-content">
                ${product.description}
            </div>
        </div>
    </div>

    <script>
        // 更新商品数量
        function updateQuantity(change) {
            const input = document.getElementById('quantity');
            let value = parseInt(input.value) + change;
            value = Math.max(1, Math.min(value, ${product.stock}));
            input.value = value;
        }

        // 加入购物车
        function addToCart(productId) {
            const quantity = document.getElementById('quantity').value;
            // TODO: 实现加入购物车功能
            alert('已添加到购物车！');
        }

        // 立即购买
        function buyNow(productId) {
            const quantity = document.getElementById('quantity').value;
            // TODO: 实现立即购买功能
            window.location.href = 'checkout?productId=' + productId + '&quantity=' + quantity;
        }

        // 切换选项卡
        function switchTab(index) {
            const headers = document.querySelectorAll('.tab-header');
            headers.forEach(header => header.classList.remove('active'));
            headers[index].classList.add('active');
            // TODO: 实现选项卡内容切换
        }
    </script>
</body>
</html> 